package com.liang.controller;


import com.liang.pojo.Userzandrolez;
import com.liang.empty.Result;
import com.liang.security.MySecurity;
import com.liang.service.RolesService;
import com.liang.service.UserandnoticeService;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;;
import java.util.List;
import com.liang.service.UserzandrolezService;
/**
 *@作者:lsk
 *Controller接口
 *@Date:2023/10/14
*/
@RestController
@RequestMapping("/UserzandrolezURL")
public class UserzandrolezController {


	@Autowired
	private UserzandrolezService userzandrolezservice;

	@Autowired
	private RolesService rolesService;


	/**
	 insert:(插入)
	*/
	@PostMapping("/insert")
	public Result insert(@RequestBody Userzandrolez demo){
		Result.buildSuccess(userzandrolezservice.insert(demo));
		return Result.buildSuccess(demo);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Userzandrolez demo){
		return Result.buildSuccess(userzandrolezservice.insertOrUpdate(demo));
	}



	/**
	 insertBath:(批量插入)
	*/
//	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Userzandrolez> list){
		return Result.buildSuccess(userzandrolezservice.insertBatch(list));
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
//	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Userzandrolez> list){
		return Result.buildSuccess(userzandrolezservice.insertOrUpdateBatch(list));
	}



	/**
	 selectList:(根据参数查询集合)
	*/
//	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		return Result.buildSuccess(userzandrolezservice.selectList(param),userzandrolezservice.selectCount(param));
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
//	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildSuccess(userzandrolezservice.selectCount(param));
	}

	/**
	 *查询一个用户的角色
	 */
	@MySecurity
	@GetMapping("/selectUserRole/{user_id}")
	public Result selectUserRole(@PathVariable(value = "user_id") Long user_id){
		return Result.buildMessage(userzandrolezservice.selectUserRole(user_id.toString()),"查询用户角色成功",200);
	}


	/**
	 * 查询一个用户的角色2-
	 */
	@MySecurity
	@PostMapping("/selectUserRoleTWO")
	public Result selectUserRoleTWO(@RequestBody Map param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",rolesService.selectCount(param));
		}
		map.put("data",userzandrolezservice.selectUserRoleTwo(param));
		return Result.buildMessage(map,"查询用户角色成功",200);
	}

	/**
	 * 删除用户角色
	 */
	@MySecurity
	@PostMapping("/deleteUserRole")
	public Result deleteUserRole(@RequestBody Map param){

		return Result.buildSuccess(userzandrolezservice.deleteUserRole(param));
	}

}